package kltn.business;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.google.android.gms.maps.model.LatLng;

public class Helper {

	static public String getMinutes(int milis){
		int sec=milis/1000;
		int min=sec/60;
		sec=sec-min*60;
		return min+":"+(sec>9?sec:"0"+sec);
	}
	static public String getVersion(Context context){
		OpenHelper h= new OpenHelper(context);
		SQLiteDatabase database=h.getReadableDatabase();
		String version="";
		Cursor c=database.query("DataBase",null,null,null,null,null,null);
		if (c.moveToNext()) {
			version= c.getString(c.getColumnIndex("Version"));
		}
		database.close();
		return version;
	}
	static public int getDistance(LatLng i1, LatLng i2) {
		double R = 6378137; // Earth�s mean radius in meter
		double dLat = rad(i2.latitude - i1.latitude);
		double dLong = rad(i2.longitude - i1.longitude);
		double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
		Math.cos(rad(i1.latitude)) * Math.cos(rad(i2.latitude)) *
		Math.sin(dLong / 2) * Math.sin(dLong / 2);
		double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
		double d = R * c;
		return (int)d; // returns the distance in meter
	};
	private static double rad(double x) {
		return x * Math.PI / 180;
	}
}
